<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/06/02
// +----------------------------------------------------------------------

namespace app\erp\model;

use think\Model;

/**
 * vip类型管理
 * @package app\erp\model
 */
class ErpVipType extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_erp_member_vip_type';

    /**
     * 添加数据
     * @param vip_name 	            string  类型名称
     * @param vip_original_price 	string  会员原价
     * @param vip_discount_price 	int     会员折扣价
     * @param month 		        string  开通月数
     * @param sort 		            int     排序
     * @author dou<51779987@qq.com>
     * @return array_out(code, message, (int)id)
     */
    public function addData($vip_name, $vip_original_price, $vip_discount_price, $month, $sort){
        $data['vip_name']               = $vip_name;
        $data['vip_original_price']     = $vip_original_price;
        $data['vip_discount_price']     = $vip_discount_price;
        $data['month']                  = $month;
        $data['sort']                   = $sort;
        $res = $this -> isUpdate(false) ->data($data, true) -> save();
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	
	/**
     * 编辑数据
     * @param id 	                string  类型id
     * @param vip_name 	            string  类型名称
     * @param vip_original_price 	string  会员原价
     * @param vip_discount_price 	int     会员折扣价
     * @param month 		        string  开通月数
     * @param sort 		            int     排序
     * @author dou<51779987@qq.com>
     * @return array_out(code, message, (int)id)
     */
	public function editData($id, $vip_name, $vip_original_price, $vip_discount_price, $month, $sort){
		$map = [];
		$map['id'] = $id;
		
		$data = [];
        $data['vip_name']               = $vip_name;
        $data['vip_original_price']     = $vip_original_price;
        $data['vip_discount_price']     = $vip_discount_price;
        $data['month']                  = $month;
        $data['sort']                   = $sort;

        $res = $this ->update($data, $map);
		if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
	}
	
	/**
     * 删除数据
     * @param int $id
     * @author dou<51779987@qq.com>
     * @return bool
     */
    public function deleteData($id){
        $res = self::destroy($id);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
}
